﻿using System;
using System.Collections.Generic;
using Co9320.NamaAlert.Model;

namespace Co9320.NamaAlert.Engine.Lists
{
	/// <summary>
	/// Rssフィーダから取得した1ページの放送一覧
	/// </summary>
	internal class FeedingLivePrograms:List<LiveProgram>
	{

		public FeedingLivePrograms(int TotalPrograms)
		{
			this.TotalPrograms = TotalPrograms;
		}

		/// <summary>
		/// このリストを作成した時点の総放送数｡
		/// -1の場合は取得失敗
		/// </summary>
		public int TotalPrograms
		{
			get;
			private set;
		}

		public DateTime? CommunityLiveFastest
		{
			get
			{
				if (base.Count == 0)
				{
					return null;
				}
				else
				{
					DateTime tmp = base[0].StartDateTime;

					for (int i = 1; i < base.Count; i++)
					{
						if (tmp < base[i].StartDateTime&&base[i].Station.Kind== StationKind.Community)
						{
							tmp = base[i].StartDateTime;
						}
					}

					return tmp;
				}

			}
		}

		public DateTime? CommunityLiveOldest
		{
			get
			{
				if (base.Count == 0)
				{
					return null;
				}
				else
				{
					DateTime tmp=base[0].StartDateTime;

					for (int i = 1; i < base.Count; i++)
					{
						if (tmp > base[i].StartDateTime&&base[i].Station.Kind== StationKind.Community)
						{
							tmp = base[i].StartDateTime;
						}
					}

					return tmp;
				}

			}
		}

		public bool HasValue
		{
			get
			{
				return base.Count != 0;
			}
		}

		public bool HasCommunity
		{
			get;
			private set;
		}

		public bool HasChannel
		{
			get;
			private set;
		}

		public bool HasOfficial
		{
			get;
			private set;
		}

		public new void Add(LiveProgram item)
		{
			switch (item.Station.Kind)
			{
				case StationKind.Channel:
					HasChannel = true;
					break;

				case StationKind.Community:
					HasCommunity = true;
					break;

				case StationKind.Official:
					HasOfficial = true;
					break;
			}


			base.Add(item);
		}
	}
}
